using System.IO;
using UnityEngine;
using UnityEngine.Networking;

namespace Assets.Scripts.GDK
{
	public class gdk_www
	{
		public static string filepath = Application.streamingAssetsPath;

		private gdk_www_component wwwComponent;

		public static gdk_www _instance = null;

		public static gdk_www Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new gdk_www();
				}
				return _instance;
			}
			set
			{
				_instance = value;
			}
		}

		public gdk_www()
		{
			GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
			gameObject.name = "[wwwNode]";
			Object.DontDestroyOnLoad(gameObject);
			wwwComponent = gameObject.AddComponent<gdk_www_component>();
		}

		public string loadTextAsset(string path)
		{
			string text = null;
			char[] array = path.ToCharArray();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].ToString().Equals("."))
				{
					text = path.Substring(0, i);
					break;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				text = path;
			}
			string path2 = Path.Combine(path, text);
			TextAsset textAsset = Resources.Load(path2) as TextAsset;
			if ((bool)textAsset)
			{
				return textAsset.text;
			}
			return null;
		}

		public string loadJson(string path)
		{
			//string text = toPath(path);
			//Debug.Log("__X__1:" + text);
			//if (text.Contains("://"))
			//{
			//	Debug.Log("__X_:2" + text);
			//	UnityWebRequest www = UnityWebRequest.Get(text);
			//	while (!www.isDone)
			//	{
			//		Debug.Log(www.downloadHandler.text);
			//	}
			//	Debug.Log(www.downloadHandler.text);
			//	return null;
			//}
			//Resources.Load(pah)
			//Debug.Log(File.ReadAllText(text));
			//return File.ReadAllText(text);
			return Resources.Load<TextAsset>(path).text;
		}

		private string toPath(string path)
		{
			return Path.Combine(filepath, path);
		}
	}
}
